package bairui.international.weixin.portal.miniapp.controller.user;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lianjing.sh.spring.web.controller.base.action.Action;
import com.lianjing.sh.spring.web.controller.enhance.output.FomatOutput;

import bairui.international.model.domain.jpa.TB_BranchCompanyStaff;
import bairui.international.model.domain.jpa.TB_User;
import bairui.international.model.status.State_User;
import bairui.international.service.Service_BranchCompanyStaff;
import bairui.international.service.Service_User;

/**
 *
 * 绑定
 *
 * @generated
 * 
 * @see STest_C_User_Bind_Get 测试
 *
 */
@Controller
public class C_User_Bind_Get
 extends SC_User_Bind_Get 
{
	
	@Autowired private Service_User service_User;
	@Autowired private Service_BranchCompanyStaff service_BranchCompanyStaff;
	
	/**
	 * Get请求
	 */
	@Action(Get.class)
	@GetMapping(Get.RequestMappingValue)
	public @FomatOutput @ResponseBody Object get(
		ModelMap map, HttpServletRequest request,
		@RequestParam Long companyStaffId,
		@RequestParam String skey
	) throws Exception {
		TB_User binder = service_User.findOne(it->it.skey.eq(skey));
		TB_BranchCompanyStaff branchCompanyStaff = service_BranchCompanyStaff.findById(companyStaffId);
		// 用户已有配送者不做绑定
		if(null != binder.getSender()){
			return null;
		}
		// 分公司员工已失效不做绑定
		if(!branchCompanyStaff.getActiveFlag() || branchCompanyStaff.getUser().getState() == State_User.Freezed){
			return null;
		}
		// 分公司员工为负责人不做绑定
		if(branchCompanyStaff.getDirectorFlag()){
			return null;
		}
//		if(parent.getType() == Type_User.General){
//			throw new ValidateObjectException("object", "", "来自不可绑定的用户类型，不做绑定处理");
//		}
		// 绑定操作
		service_User.bindSender(binder, branchCompanyStaff);
		//
		return null;
	}
	

}
